1 module hip.api.renderer.vertex; 2 import hip.api.renderer.shader; 3 4 // version(Android){alias index_t = ushort;} 5 // else{alias index_t = uint;} 6 alias index_t = ushort; 7 8 9 index_t index_t_maxQuads() 10 { 11 return cast(index_t)(ushort.max / 6); 12 } 13 index_t index_t_maxQuadIndices() 14 { 15 return cast(index_t)(index_t_maxQuads * 6); 16 } 17 18 /** 19 * Information about how the resource is used. 20 */ 21 enum HipResourceUsage : ubyte 22 { 23 ///Usually means the resource is able to change, but with subpar speed 24 Default, 25 ///Means that the resource is optimized to be changed from the CPU 26 Dynamic, 27 ///The resource is immutable and can't be changed 28 Immutable, 29 } 30 31 enum HipAttributeType : ubyte 32 { 33 ///Used as a unsigned r8g8b8a8 normalized type. 34 Rgba32, 35 Float, 36 Uint, 37 Int, 38 Bool 39 } 40 41 42 struct HipVertexAttributeInfo 43 { 44 uint index; 45 uint count; 46 uint offset; 47 uint typeSize; 48 HipAttributeType valueType; 49 string name; 50 } 51 52 enum HipRendererBufferType : ubyte 53 { 54 index, 55 vertex 56 } 57 58 interface IHipRendererBuffer 59 { 60 HipRendererBufferType type() const; 61 void bind(); 62 void unbind(); 63 void setData(const void[] data); 64 /** 65 * This API is not available on OpenGL. Use set/update data instead. 66 * Returns: The mapped GPU buffer 67 */ 68 ubyte[] getBuffer(); 69 /** 70 * This API is only necessary when dealing with D3D. The buffer is automatically mapped when getBuffer is called. 71 */ 72 void unmapBuffer(); 73 void updateData(int offset, const void[] data); 74 } 75 76 77 interface IHipVertexArrayImpl 78 { 79 void bind(IHipRendererBuffer vbo, IHipRendererBuffer ebo); 80 void unbind(IHipRendererBuffer vbo, IHipRendererBuffer ebo); 81 /** 82 * GL also needs to bind both the vertex and index buffer before creatting the input layout 83 * Direct3D 11 needs vertex shader information for creating a VAO 84 * Metal needs a ShaderProgram for cerating a pipelinestate 85 */ 86 void createInputLayout( 87 IHipRendererBuffer vbo, IHipRendererBuffer ebo, 88 HipVertexAttributeInfo[] info, uint stride, 89 VertexShader vertexShader, 90 ShaderProgram shaderProgram 91 ); 92 } 93